<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file="common/head" /}
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form action="" id="form" class="layui-form" method="post">
            <input type="hidden" name="cat_id" value="{$info.cat_id|default=0}">
            <div class="layui-form-item">
                <label for="parent_id" class="layui-form-label">
                    <span class="x-red">*</span>上级
                </label>
                <div class="layui-input-inline">
                    <div class="layui-input-inline">
                        <select id="parent_id" name="parent_id" lay-filter="parent_id">
                            <option value="0">作为一级分类</option>
                            {foreach $plist as $key=>$vo }
                            {neq name="vo['cat_id']" value="$id"}
                            <option value="{$vo['cat_id']}">{$vo.cat_name}</option>

                            {notempty name="vo['child']"}
                            {foreach $vo['child'] as $k1=>$two}
                            <option value="{$two['cat_id']}">&nbsp;&nbsp;├{$two.cat_name}</option>

                            {notempty name="two['child']"}
                            {foreach $two['child'] as $k1=>$three}
                            <option value="{$three['cat_id']}">&nbsp;&nbsp;&nbsp;&nbsp;├{$three.cat_name}</option>
                            {/foreach}
                            {/notempty}

                            {/foreach}
                            {/notempty}
                            {/neq}
                            {/foreach}
                        </select>

                        {empty name='pid'}
                        <script>$("#parent_id option[value = '{$info.parent_id}']").attr("selected","selected");</script>
                        {else /}
                        <script>$("#parent_id option[value = '{$pid}']").attr("selected","selected");</script>
                        {/empty}

                    </div>
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="cat_name" class="layui-form-label">
                    <span class="x-red">*</span>分类名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info.cat_name}" id="cat_name" name="cat_name" required="" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="cat_alias" class="layui-form-label">
                    <span class="x-red"></span>分类别名
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info.cat_alias}" id="cat_alias" name="cat_alias" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="cat_alias" class="layui-form-label">
                    <span class="x-red">*</span>分类标识
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info.cat_key}" id="cat_key" name="cat_key" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">不能重复，前台取指定栏目使用</span>

                </div>
            </div>

            <div class="layui-form-item">
                <label for="keywords" class="layui-form-label">
                    <span class="x-red"></span>搜索关键词
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info.keywords}" id="keywords" name="keywords" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red"></span>状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" {eq name="info['status']" value="1"}checked{/eq} lay-skin="primary" title="显示" checked="">
                    <input type="radio" name="status" value="0" {eq name="info['status']" value="0"}checked{/eq} lay-skin="primary" title="隐藏">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="cat_desc" class="layui-form-label">
                    <span class="x-red"></span>备注
                </label>
                <div class="layui-input-inline">
                    <textarea id="cat_desc" name="cat_desc" placeholder="请输入内容" class="layui-textarea">{$info.cat_desc}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="ok" class="layui-form-label">
                </label>
                <button id="ok" class="layui-btn" lay-filter="add" lay-submit="">
                    {empty name="info['cat_id']"}
                    增  加
                    {else /}
                    修  改
                    {/empty}

                </button>
            </div>
        </form>
    </div>
</div>

<div id="idbox" style="display: none">

</div>
<script>layui.use(['form', 'layer'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //自定义验证规则
        form.verify({
            zm: function(value) {
                if(!new RegExp("^[a-zA-Z0-9_\s·]+$").test(value)){
                    return '只能是字母或数字，字母和下划线开头';
                }

                if(!isNaN(value.substr(0,1))){
                    return '只能是字母或数字，字母和下划线开头';
                }
            }
        });

        //监听提交
        form.on('submit(add)',
            function(data) {
                $.ajax({
                    type: "POST",
                    url: "{:url()}",
                    data: data.field,
                    success: function (result) {
                        layer.alert(result.msg, {
                            icon: 6
                        },function() {
                            xadmin.close();
                            xadmin.father_reload();
                        });
                    },
                    error: function(data) {
                        layer.alert(data.msg, {
                            icon: 2
                        },function() {
                            xadmin.close();
                        });
                    }

                });
                return false;
            });
    });
</script>

</body>

</html>
